﻿using Furion;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;
using XinGuanERP.Attributes.system;
using XinGuanERP.Models.Vo.system;
using XinGuanERP.Services.system.IServices;
using XinGuanERP.Utils;

namespace XinGuanERP.Controllers.system
{
    [DynamicApiController]
    public class UserController
    {
        private readonly IUserService _userService;

        public UserController(IUserService userService)
        {
            _userService = userService;
        }

        [Authorize]
        [ServiceFilter(typeof(MyActionFilterAttribute))]
        public ResultUtil PostUser(UserVo viewUser) =>
            ResultUtil.ok(_userService.UpdateUser(viewUser));

        [Authorize]
        [ServiceFilter(typeof(MyActionFilterAttribute))]
        public ResultUtil GetUserWithList(string? deptId, string? userName, string? realName)
        {

            return ResultUtil.ok(_userService.GetUserWithList(deptId!, userName, realName));

        }

        [Authorize]
        [ServiceFilter(typeof(MyActionFilterAttribute))]
        public ResultUtil GetUserWithPage(int page, int pageSize, string? deptId, string? userName, string? realName)
        {
            return ResultUtil.ok(_userService.GetUserWithPage(page, pageSize, deptId, userName, realName));
        }

        [Authorize]
        [ServiceFilter(typeof(MyActionFilterAttribute))]
        [HttpPut]
        public ResultUtil ResetToDefaultPassword(string userId)
            => ResultUtil.ok(_userService.ResetToDefaultPassword(userId));

        [Authorize]
        [ServiceFilter(typeof(MyActionFilterAttribute))]
        public ResultUtil DeleteUser(string userId) => ResultUtil.ok(_userService.DeleteUser(userId));

        [Authorize]
        [ServiceFilter(typeof(MyActionFilterAttribute))]
        public ResultUtil GetUserDetail(string userId) => ResultUtil.ok(_userService.GetUserByUserId(userId));
    }
}
